<?php
include("../mysqlcon.php");
mysql_select_db($dbname,$conn);
mysql_query('SET NAMES utf8');
//$reserv_id = $_GET['reserv_id'];
$keyValidate = null;
$current = date("Y-m-d",strtotime("Today"));
if($_GET['reserv_gid'] != null){
	$temp = $_GET['reserv_gid'];
	$keyValidate = 'reservgroup.reserv_gid = '.$temp;
}elseif($_GET['customer_name'] != null){
	$temp = $_GET['customer_name'];
	$keyValidate = "customer.customer_name LIKE '%".$temp."%'";
}elseif($_GET['customer_surname'] != null){
	$temp = $_GET['customer_surname'];
	$keyValidate = "customer.customer_surname LIKE '%".$temp."%'";
}
$validatesql = "SELECT reserv_id,reserv_begin,reserv_end,room_id,customer.customer_id,customer.id,customer_name,customer_surname,customer_email,customer_tel,customer_fax,reservgroup.reserv_gid,reservgroup.room_list,reservgroup.reserv_gcost,reservgroup.reserv_cashpledge 
				FROM reservation
				INNER JOIN reservgroup ON ( reservation.reserv_gid = reservgroup.reserv_gid )
				INNER JOIN customer ON ( reservation.id = customer.id ) 
				WHERE $keyValidate AND reserv_status BETWEEN '0' AND '3' GROUP BY reserv_gid";

//echo $validatesql;

//$validatesql = "SELECT reserv_id,reserv_begin,reserv_end,room_id,customer.customer_id,customer.id,customer_name,customer_surname,customer_email,customer_tel,customer_fax FROM reservation,customer 
//WHERE reserv_id = '$reserv_id' AND reservation.id = customer.id AND reserv_status = '0'";

	$r = mysql_query($validatesql,$conn);
	echo "[";
	while ($rs = mysql_fetch_array($r))
	{
	   if($current != $rs['reserv_begin'])
	      $rs['reserv_begin'] = '<b style="color:red;">' . $rs['reserv_begin'] . '</b>';
	   echo "{reserv_gid: '".$rs['reserv_gid']."', reserv_begin: '".$rs['reserv_begin']."', reserv_end: '".$rs['reserv_end']."', room_list: '".$rs['room_list']."', customer_id: '".$rs['customer_id']."', cid: '".$rs['id']."', customer_name: '".$rs['customer_name']."', customer_surname: '".$rs['customer_surname']."', customer_email: '".$rs['customer_email']."', customer_tel: '".$rs['customer_tel']."', customer_fax: '".$rs['customer_fax']."', reserv_gcost: '".$rs['reserv_gcost']."', reserv_cashpledge: '".$rs['reserv_cashpledge']."'}, ";
	}
	echo "]";
?>
